// pages/mycoupon/mycoupon.js
var ports = require("../../utils/ports.js")
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    status: 1
  },
  onLoad: function (options) {
    this.getMyMemberBonusList()
  },
  changeStatus(e) {
    var that = this
    var curStatus = parseInt(that.data.status)
    var status = parseInt(e.currentTarget.dataset.status)
    if (curStatus == status) {
      return
    }
    that.setData({
      status,
      MemberBonusListPage: [],
      MemberBonusList: []
    })
    that.getMyMemberBonusList()
  },
  //红包列表
  getMyMemberBonusList() {
    var that = this
    wx.showToast({
      title: '加载中',
      icon: 'loading',
      mask: true
    })
    var req = {}
    req.status = that.data.status
    ports.ModuleBonus.getMyMemberBonusList(req, that, res => {
      wx.hideToast()
      if (res.data.header.code == 0) {
        that.setData({
          MemberBonusListPage: res.data.body.data.rows,
          MemberBonusList: res.data.body.data.rows
        })
      } else {
        wx.showToast({
          title: '获取列表失败',
          icon: 'none'
        })
      }
    })
  },
  onPullDownRefresh: function () {
    var that = this;
    ports.ModuleAll.PullDownRefresh(that, () => {
      that.getMyMemberBonusList();
    })
  },
  onReachBottom: function () {
    var that = this;
    ports.ModuleAll.ReachBottom('MemberBonusList', that, res => {
      that.getMyMemberBonusList();
    })
  },
  category() {
    wx.switchTab({
      url: '/pages/classify/classify',
    })
  }
})